#!/usr/bin/ruby
# -*- ruby -*-
#
# http://www.reddit.com/r/dailyprogrammer/comments/106gse/9202012_challenge_100_intermediate_bad_word_filter/

require 'optparse'

wordlist = File.basename($0).gsub(/\.rb$/, '.input')

OptionParser.new do |o|
  o.on("--wordlist=WORDLIST", String) { |wordlist| }
end.parse!

patterns = {}

File.open(wordlist) do |wordlist_fh|
  wordlist_fh.readlines.each do |word|
    word.strip!

    patterns[word] = word.slice(0, 1) + ('*' * (word.size - 1))
  end
end

STDIN.read.split("\n").each do |line|
  line.strip!

  # Ok, not exactly my most efficient moment, but it works.
  patterns.each_pair do |pattern, replace|
    line.gsub!(pattern, replace)
  end

  puts line
end
